<script src="<?php echo $this->basePath('js/plugins/clipboard/clipboard.min.js')?>"></script>
<div class="content-wrapper">
    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>
        <h1 class="pull-right">
            <a href="<?php echo $this->url('goods-class', ['action'=> 'add']);?>" class="btn btn-primary btn-sm"><i class="fa fa-plus"></i> <?php echo $this->translate('添加分类'); ?></a>
            <a href="<?php echo $this->url('goods-class', ['action'=> 'add'], ['query' => ['type' => 'addMore']]);?>" class="btn btn-primary btn-sm"><i class="fa fa-list"></i> <?php echo $this->translate('批量添加分类'); ?></a>
            <?php echo $this->HelpUrl('goodsClassList'); ?>
        </h1>
    </section>

    <section class="content">
        <?php echo $this->partial('layout/messages'); ?>

        <div class="row">
            <div class="col-xs-12">
                <div class="box shop-box">
                    <form method="post" action="<?php echo $this->url('goods-class', ['action' => 'updateAllSort']);?>" name="edit-all-form" id="edit-all-form">
                    <div class="box-body table-responsive no-padding">
                        <table class="table shop-table table-hover">
                            <thead>
                            <tr class="shop-bg-thead">
                                <th width="2%"><input type="checkbox" class="minimal select-all-checkbox"></th>
                                <th width="28%"><?php echo $this->translate('商品分类名称 (分类ID)'); ?></th>
                                <th width="5%"><?php echo $this->translate('商品数量'); ?></th>
                                <th width="5%"><?php echo $this->translate('排序'); ?></th>
                                <th width="5%"><?php echo $this->translate('状态'); ?></th>
                                <th width="12%"><?php echo $this->translate('操作'); ?></th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php if($this->class) foreach ($this->class as $value) { ?>
                                <tr>
                                    <td><input  name="select_id[]" value="<?php echo $value[0]->getClassId(); ?>" type="checkbox" class="minimal"></td>
                                    <td>
                                        <?php if($value[0]->getClassTopId() > 0) echo str_repeat('&nbsp;', substr_count($value[0]->getClassPath(), ',') * 3); ?>|----
                                        <?php echo $this->escapeHtml($value[0]->getClassName() . ' (ID：' . $value[0]->getClassId() . ')'); ?>
                                    </td>
                                    <td id="goodsNum_<?php echo $value[0]->getClassId(); ?>">
                                        <?php echo $value['goodsNum']; ?>
                                    </td>
                                    <td><input type="number" name="classSort[<?php echo $value[0]->getClassId(); ?>]" value="<?php echo $this->escapeHtml($value[0]->getClassSort()); ?>" class="form-control input-sm"></td>
                                    <td><?php echo $this->goodsHelper()->goodsClassState($value[0]->getClassState()); ?></td>
                                    <td>
                                        <a href="<?php echo $this->url('goods-class', ['action'=>'edit', 'id'=>$value[0]->getClassId()]); ?>" class="btn btn-xs btn-success"><i class="fa fa-pencil"></i> <?php echo $this->translate('编辑'); ?></a>

                                        <input type="hidden" name="classUrl<?php echo $value[0]->getClassId(); ?>" id="classUrl<?php echo $value[0]->getClassId(); ?>" value="<?php echo $this->url('shop-class', ['action'=>'goodsList', 'id' => $value[0]->getClassId()], ['force_canonical' => true]); ?>">
                                        <button type="button" id="btn-copy-classUrl<?php echo $value[0]->getClassId(); ?>" onclick="copyClassUrl(<?php echo $value[0]->getClassId(); ?>);" class="btn btn-xs btn-primary"><i class="fa fa-files-o" aria-hidden="true"></i> <?php echo $this->translate('复制前台链接'); ?></button>

                                        <a href="javascript:;" onclick="deleteConfirm('<?php echo $this->translate('您确实要删除该分类吗?'); ?>', '<?php echo $this->url('goods-class', ['action'=>'delete', 'id'=>$value[0]->getClassId()], ['query' => ['qToken' => $this->adminHelper()->getCsrfValue()]]); ?>');" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i> <?php echo $this->translate('删除'); ?></a>
                                    </td>
                                </tr>
                            <?php } ?>
                            </tbody>
                        </table>
                    </div>
                        <div class="box-footer clearfix">
                            <input type="checkbox" class="minimal select-all-checkbox"> <?php echo $this->translate('全选'); ?>
                            <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-check"></i> <?php echo $this->translate('更新'); ?></button>
                        </div>
                    </form>

                </div>
            </div>
        </div>
    </section>
</div>
<script type="text/javascript">
    function copyClassUrl(classId) {
        let clipboard = new ClipboardJS('#btn-copy-classUrl'+classId, { text: function() { return $('#classUrl'+classId).val() }});
        clipboard.on('success', function (e) {
            layer.msg('复制完成！');
            clipboard.destroy();
        });
        clipboard.on('error', function (e) {
            layer.msg('复制不成功，请您手动进行复制！');
        });
    }
</script>